import 'package:flutter/material.dart';

import 'game.dart';
import 'gift.dart';
import 'home.dart';
import 'my.dart';
import 'news.dart';

class Maintab extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<Maintab> {
  int _tabIndex = 0;
  var appBarTitles = ['首页', '游戏', '礼包', '咨询', '我的'];
  List<BottomNavigationBarItem> _navigationViews;
  final _pages = [Home(), Game(), Gift(), News(), My()];

  initData() {}

  @override
  void initState() {
    super.initState();

    _navigationViews = <BottomNavigationBarItem>[
      new BottomNavigationBarItem(
        icon: const Icon(Icons.home),
        label: appBarTitles[0],
        backgroundColor: Colors.blue,
      ),
      new BottomNavigationBarItem(
        icon: const Icon(Icons.videogame_asset_sharp),
        label: appBarTitles[1],
        backgroundColor: Colors.blue,
      ),
      new BottomNavigationBarItem(
        icon: const Icon(Icons.card_giftcard_sharp),
        label: appBarTitles[2],
        backgroundColor: Colors.blue,
      ),
      new BottomNavigationBarItem(
        icon: const Icon(Icons.event_note_sharp),
        label: appBarTitles[3],
        backgroundColor: Colors.blue,
      ),
      new BottomNavigationBarItem(
        icon: const Icon(Icons.person),
        label: appBarTitles[4],
        backgroundColor: Colors.blue,
      )
    ];
  }

  final navigatorKey = GlobalKey<NavigatorState>();

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,
      theme: new ThemeData(primaryColor: Colors.blue, accentColor: Colors.blue),
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text(
            appBarTitles[_tabIndex],
            style: new TextStyle(color: Colors.white),
          ),
        ),
        body: _pages[_tabIndex],
        bottomNavigationBar: BottomNavigationBar(
          items: _navigationViews,
          currentIndex: _tabIndex,
          type: BottomNavigationBarType.fixed,
          onTap: (index) {
            _changePage(index);
          },
        ),
      ),
    );
  }

  void _changePage(int index) {
    if (index != _tabIndex) {
      setState(() {
        _tabIndex = index;
      });
    }
  }
}
